package com.molyfun.parents.activity.msg;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.molyfun.parents.R;
import com.molyfun.parents.activity.MainActivity;
import com.molyfun.parents.activity.common.BaseActivity;
import com.molyfun.parents.rest.bean.MsgListResponse;
import com.molyfun.parents.utils.Const;
import com.molyfun.parents.utils.TimeUtils;

import butterknife.ButterKnife;
import butterknife.InjectView;

/**
 * Created by william(liuchao.hit@gmail.com).
 * Date:11/30/16.
 */
public class MsgActivity extends BaseActivity implements View.OnClickListener{

    @InjectView(R.id.msg_content)
    TextView mMsgContent;
    @InjectView(R.id.msg_from_time)
    TextView mMsgFromTime;
    @InjectView(R.id.msg_more)
    TextView mMsgMore;
    @InjectView(R.id.base_title_left)
    ImageView mTitleLeft;
    @InjectView(R.id.base_title)
    TextView mTitle;

    private MsgListResponse.MsgBean mMsgBean;

    public static final void startActivity(Context context, MsgListResponse.MsgBean msgBean){
        Intent intent = new Intent();
        intent.setClass(context, MsgActivity.class);
        intent.putExtra(Const.MSG_BEAN, msgBean);
        context.startActivity(intent);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_msg);
        ButterKnife.inject(this);

        getSupportActionBar().setTitle("");
        mTitle.setText("消息");

        mMsgBean = getIntent().getParcelableExtra(Const.MSG_BEAN);
        if(mMsgBean == null){
            return;
        }
        mMsgContent.setText(mMsgBean.getContent());
        mMsgFromTime.setText("----" + mMsgBean.getFromusername() + " " + TimeUtils.transForDate(mMsgBean.getCreatedatetime()));
        String code=mMsgBean.getCode();
        if (!"".equals(code) || code!=null){
            if ("ZYAPZD".equals(code) || "KTBX".equals(code) || "ZXHF".equals(code)){
                mMsgMore.setVisibility(View.VISIBLE);
                mMsgMore.setOnClickListener(this);
            }
        }
        mTitleLeft.setOnClickListener(this);

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.base_title_left:
                finish();
                break;
            case R.id.msg_more:
                Intent intent = null;
                String code= mMsgBean.getCode();
                switch (code) {
                    case "ZYAPZD":
                        //作业,根据detailid的时间跳转
                        intent = new Intent(MsgActivity.this, MainActivity.class);
                        intent.putExtra(Const.DETAIL_ID, mMsgBean.getDetailid());
                        intent.putExtra(Const.MAIN_CHOOSED_TAB, Const.MAIN_TAB_HOMEWORK);
                        break;
                    case "KTBX":
                        //课程,根据detailid的时间跳转
                        intent = new Intent(MsgActivity.this, MainActivity.class);
                        intent.putExtra(Const.DETAIL_ID, mMsgBean.getDetailid());
                        intent.putExtra(Const.MAIN_CHOOSED_TAB, Const.MAIN_TAB_COURSE);
                        break;
                    case "ZXHF":
                        //问题
//                        TopicDetailActivity.startActivity(MsgActivity.this, mMsgBean.getDetailid(), AskTopBar.AskBarChooseTab.BAR_MINE);
//                        intent = new Intent(MsgActivity.this, TopicDetailActivity.class);
//                        intent.putExtra(Const.DETAIL_ID, mMsgBean.getDetailid());
                        break;
                    case "RXSB":
                        //报名失败
                        toast("报名失败");
                        break;
                }
                if(intent != null){
                    startActivity(intent);
                }

                break;
        }
    }

}
